package cc.decat.escript.object;

public class ESType extends ESObject {

    private final String name; // type name

    public ESType(String name) {
        super(ESTypeType.getInstance());
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public ESObject add(ESObject lhs, ESObject rhs) {
        System.err.printf("TypeError: unsupported operand type(s) for +: '%s' and '%s'", lhs.getType().getName(), rhs.getType().getName());
        return ESConstObjects.NULL;
    }
    public ESObject sub(ESObject lhs, ESObject rhs) {
        System.err.printf("TypeError: unsupported operand type(s) for -: '%s' and '%s'", lhs.getType().getName(), rhs.getType().getName());
        return ESConstObjects.NULL;
    }
    public ESObject mul(ESObject lhs, ESObject rhs) {
        return ESConstObjects.NULL;
    }
    public ESObject div(ESObject lhs, ESObject rhs) {
        return ESConstObjects.NULL;
    }
    public ESObject mod(ESObject lhs, ESObject rhs) {
        return ESConstObjects.NULL;
    }

    public ESObject eq(ESObject lhs, ESObject rhs) {
        return ESBooleanObject.fromValue(lhs == rhs);
    }
    public ESObject neq(ESObject lhs, ESObject rhs) {
        return ESBooleanObject.fromValue(lhs != rhs);
    }
    public ESObject lt(ESObject lhs, ESObject rhs) {
        return ESConstObjects.NULL;
    }
    public ESObject lte(ESObject lhs, ESObject rhs) {
        return ESConstObjects.NULL;
    }
    public ESObject gt(ESObject lhs, ESObject rhs) {
        return ESConstObjects.NULL;
    }
    public ESObject gte(ESObject lhs, ESObject rhs) {
        return ESConstObjects.NULL;
    }

    public ESObject getSubscr(ESObject lhs, ESObject rhs) {
        return ESConstObjects.NULL;
    }

    public void setSubscr(ESObject lhs, ESObject mhs, ESObject rhs) {
    }

    public void deleteSubscr(ESObject lhs, ESObject rhs) {
    }

    public ESObject str(ESObject x) {
        return ESStringObject.fromValue(name);
    }

    public ESObject len(ESObject x) {
        return ESConstObjects.NULL;
    }

    public ESObject getAttr(ESObject lhs, String rhs) {
        if(lhs == ESConstObjects.NULL) {
            throw new RuntimeException("can't get attribute for null");
        }
        if(!lhs.getAttributes().containsKey(rhs)) {
            return ESConstObjects.NULL;
        }
        return lhs.getAttributes().get(rhs);
    }

    public void setAttr(ESObject lhs, String mhs, ESObject rhs) {
        if(lhs == ESConstObjects.NULL) {
            throw new RuntimeException("can't set attribute for null");
        }
        lhs.getAttributes().put(mhs, rhs);
    }
}

class ESTypeType extends ESType {

    private static final ESTypeType instance = new ESTypeType();

    public static ESTypeType getInstance() {
        return instance;
    }

    private ESTypeType() {
        super("Type");
    }
}
